<?php
/*
 * Copyright 2013 by Jerrick Hoang, Ivy Xing, Sam Roberts, James Cook, 
 * Johnny Coster, Judy Yang, Jackson Moniaga, Oliver Radwan, 
 * Maxwell Palmer, Nolan McNair, Taylor Talmage, and Allen Tucker. 
 * This program is part of RMH Homebase, which is free software.  It comes with 
 * absolutely no warranty. You can redistribute and/or modify it under the terms 
 * of the GNU General Public License as published by the Free Software Foundation
 * (see <http://www.gnu.org/licenses/ for more information).
 * 
 */

/*
 * 	personForm.inc
 *  shows a form for a person to be added or edited in the database
 * 	@author Adam and Neil
 *              5/7/14
 */

if ($_SESSION['access_level'] == 0) {
    echo('<p><strong>New Clinician Application Form</strong><br />');
    echo('Please provide us with some basic information about yourself and your interests.' .
    '<br>When you are finished, hit <b>Submit</b> at the bottom of this page.');
} else if ($_SESSION['access_level'] == 1)
    if ($_SESSION['_id'] != $person->get_id()) {
        echo("<p id=\"error\">You do not have sufficient permissions to edit this user.</p>");
        include('footer.inc');
        echo('</div></div></body></html>');
        die();
    } else {
        echo('<p><strong>Clinician Edit Form</strong><br />');
        echo('Here you can edit your own information in the database.' .
        '<br>When you are finished, hit <b>Submit</b> at the bottom of this page.');
    } else if ($_SESSION['access_level'] == 2)
    if ($id == 'new') {
        echo('<p><strong>New Clinician Form</strong><br />');
        echo('Here you can add a new clinician into the database. </p>');
    } else {
        echo('<p><strong>Clinician Edit Form</strong><br />');
        echo('Here you can edit, delete, or change the password for a clinician in the database.</p><p>');
    } else {
    echo("<p id=\"error\">You do not have sufficient permissions to add a new person to the database.</p>");
    include('footer.inc');
    echo('</div></div></body></html>');
    die();
}
?>
<form method="POST">
    <input type="hidden" name="old_id" value=<?PHP echo("\"" . $id . "\""); ?>>
    
    <input type="hidden" name="_form_submit" value="1">
    <p>(<span style="font-size:x-small;color:FF0000">*</span> denotes required fields)
    <p>First Name<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="first_name" tabindex="1" value="<?PHP echo($person->get_fname()) ?>">
        Last Name<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="last_name" tabindex="2" value="<?PHP echo($person->get_lname()) ?>">
    <fieldset>
        <legend>Contact information:</legend>
        

        <p>Phone<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="phone1" MAXLENGTH=12 tabindex="3" value="<?PHP echo($person->get_phoneNum()) ?>">
            &nbsp;&nbsp;Cell Phone:<input type="text" name="phone2" MAXLENGTH=12 tabindex="4" value="<?PHP echo($person->get_cellNum()) ?>">
       
        <p>Specialty<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="specialty" tabindex="5" value="<?PHP echo($person->get_specialty()) ?>">


    <fieldset id='availability'>
        <legend>Availability:</legend>
        <span class="bigTable">
            <table>
                <?PHP
                $shifts = array('morning' => 'Morning (9-12)', 'earlypm' => 'Early afternoon (12-3)', 'latepm' => 'Late afternoon (3-6)',
                    'evening' => 'evening (6-9)', 'overnight' => "Overnight");
                $days = array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
                //$person_availability = implode(',', $person->get_availability());
    			echo "<table>".
					"<tr><td> &nbsp;&nbsp;</td><td>Mon&nbsp;&nbsp;</td><td>Tue&nbsp;&nbsp;</td><td>Wed&nbsp;&nbsp;</td>".
					"<td>Thu&nbsp;&nbsp;</td><td>Fri&nbsp;&nbsp;</td><td>Sat&nbsp;&nbsp;</td><td>Sun</td></tr>";
    			foreach ($shifts as $weekno => $weekvalue) {
       				echo ('<tr><td>'. $weekvalue . '</td>');
       				foreach ($days as $day) {
       	  				$realkey = $day . ":". $weekno;
       	  				echo ('<td><input type="checkbox" name="availability[]" value=' . $realkey);
    	  				//if (in_array($day.":".$weekno, $person->get_availability())) echo(' CHECKED');
    	  				echo ('></td>');
       				}
       				echo ('</tr>');
    			}
   		 		echo "</table><p>";
    			?>
            </table>
        </span></p>
    </fieldset>
    <p>
        <?PHP


        //echo('<input type="hidden" name="schedule" value="' . implode(',', $person->get_availability()) . '">');
        //echo('<input type="hidden" name="password" value="' . $person->get_password() . ')">');
        echo('<input type="hidden" name="_submit_check" value="1"><p>');
        if ($_SESSION['access_level'] == 0)
            echo('Hit <input type="submit" value="Submit" name="Submit Edits"> to complete this application.<br /><br />');
        else
            echo('Hit <input type="submit" value="Submit" name="Submit Edits"> to submit these edits.<br /><br />');
        if ($id != 'new' && $_SESSION['access_level'] >= 2) {
            echo ('<input type="checkbox" name="deleteMe" value="DELETE"> Check this box and then hit ' .
            '<input type="submit" value="Delete" name="Delete Entry"> to delete this entry. <br />' .
            '<input type="checkbox" name="reset_pass" value="RESET"> Check this box and then hit ' .
            '<input type="submit" value="Reset Password" name="Reset Password"> to reset this person\'s password.</p>');
        }

        function &select_date($month, $day, $year, $month_name, $day_name, $year_name) {
            $months = array('', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
            echo('<select name=' . $month_name . '><option value=""></option>');
            echo('');
            for ($i = 1; $i <= 12; $i++) {
                echo '<option value=' . (($i < 10) ? "0" . $i : $i);
                if ($month == $i)
                    echo(' SELECTED');
                echo '>' . $months[$i] . ' </option>';
            }
            echo "</select>";

            echo '<select name=' . $day_name . '><option value=""></option>';
            for ($i = 1; $i <= 31; $i++) {
                echo '<option value=' . (($i < 10) ? "0" . $i : $i);
                if ($day == $i)
                    echo(' SELECTED');
                echo '>' . $i . ' </option>';
            }
            echo "</select>";
            // handles a year range of 81 years, from today+1 to today-80
            echo '<select name=' . $year_name . '><option value=""></option>';
            $start_year = date("Y")+1;
            for ($i = $start_year; $i >= ($start_year - 90); $i--) {
                echo '<option value=' . substr($i, 2, 2);
                if ($year == substr($i, 2, 2))
                    echo(' SELECTED');
                echo '>' . $i . ' </option>';
            }
            echo "</select>";
        }
        ?>
</form>

